#include "StdAfx.h"
#include "VSqlMetaView.h"

// VSqlMetaView ///////////////////////////////////////////////////////////////

//
VSqlMetaView::VSqlMetaView(QWidget *parent)
	:QFrame(parent)
	,m_view(NULL)
	,m_model(NULL)
	,m_proxyModel(NULL)
{
	//m_proxyModel = new QSortFilterProxyModel(this);
		//m_treeProxyModel->setSourceModel(m_model);
		//m_treeProxyModel->setFilterRole(Qt::DisplayRole);
		//m_treeProxyModel->setFilterKeyColumn(0);
		//m_treeProxyModel->setFilterFixedString("1");
	m_view = new QTreeView(this);
		//m_view->setModel(m_proxyModel);
		//m_view->setItemDelegate(new VItemDelegate(m_view));
		m_view->setAlternatingRowColors(true);
		m_view->setExpandsOnDoubleClick(true);
		m_view->setSelectionBehavior(QAbstractItemView::SelectRows);
		m_view->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
		m_view->setAnimated(false);
		//m_view->setAllColumnsShowFocus(true);
		m_view->setEditTriggers(
			//QAbstractItemView::NoEditTriggers 
			QAbstractItemView::DoubleClicked
		);
		m_view->setRootIsDecorated(true); 
		m_view->setItemsExpandable(true);

		//m_view->setSelectionMode(QAbstractItemView::ExtendedSelection);
		//m_view->setAutoExpandDelay(10);
		//m_view->setDragEnabled(true);
		//m_view->setAcceptDrops(true);
		//m_view->setDropIndicatorShown(true);
		//m_view->expandAll();

	QVBoxLayout *mainLayout = new QVBoxLayout(this);
		mainLayout->setContentsMargins(0,0,0,0);
		mainLayout->addWidget(m_view);
	setLayout(mainLayout);

	VSettings settings("VSqlMetaView");
		m_view->header()->restoreState(
			settings.value("view/header/state",m_view->header()->saveState()).toByteArray()
		);
}

//
VSqlMetaView::~VSqlMetaView()
{
	VSettings settings("VSqlMetaView");
		settings.setValue("view/header/state",m_view->header()->saveState());
}

//
void VSqlMetaView::setModel(VSqlMetaModel *model)
{
	m_model = model;
	m_view->setModel(m_model);
	//m_proxyModel->setSourceModel(m_model);
}
